import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getLoginUserUsingGet } from '@/api/userController.ts'

export const  useLoginUserStore = defineStore("user",()=>{

  const loginUser = ref<API.LoginUserVo>({
    userName:"为登录"
  })


  function setLoginUser(newLoginUser:any){
    loginUser.value = newLoginUser
  }


  async function  fetchLoginUser(){

    let res = await getLoginUserUsingGet()

    if (res.data.code === 0 && res.data.data){
      loginUser.value = res.data.data
    }
    // setTimeout(()=>{
    //   loginUser.value = {
    //     id:1,
    //     userName:"waterkid"
    //   }
    // },3000)
  }


  return {loginUser,setLoginUser,fetchLoginUser}
})
